package com.terracloud.server.dao.model.sql;

import com.terracloud.server.common.data.DeviceGroup;
import com.terracloud.server.common.data.DeviceGroupRelation;
import com.terracloud.server.common.data.id.DeviceGroupId;
import com.terracloud.server.common.data.id.DeviceGroupRelationId;
import com.terracloud.server.common.data.id.TenantId;
import com.terracloud.server.dao.model.BaseSqlEntity;
import com.terracloud.server.dao.model.BaseVersionedEntity;
import com.terracloud.server.dao.model.ModelConstants;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.UUID;

import static org.springframework.data.jpa.domain.AbstractPersistable_.id;

/**
 *
 * @author chenhainan
 * @since 2025/10/11
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = ModelConstants.DEVICE_GROUP_RELATION_TABLE_NAME)
public class DeviceGroupRelationEntity extends BaseSqlEntity<DeviceGroupRelation> {

    @Column(name = "device_id")
    private UUID deviceId;

    @Column(name = "device_group_id")
    private UUID deviceGroupId;

    public DeviceGroupRelationEntity(UUID deviceId, UUID deviceGroupId) {
        this.deviceId = deviceId;
        this.deviceGroupId = deviceGroupId;
    }

    public DeviceGroupRelationEntity() {
    }

    @Override
    public DeviceGroupRelation toData() {
        final var deviceGroupRelation = new DeviceGroupRelation();
        deviceGroupRelation.setDeviceGroupId(deviceGroupId);
        deviceGroupRelation.setDeviceId(deviceId);
        deviceGroupRelation.setId(new DeviceGroupRelationId(id));
        deviceGroupRelation.setCreatedTime(createdTime);
        return deviceGroupRelation;
    }
}
